import requests
from tools.funciton import *
import pymongo
from config.configs import ALPHA_DB_HOST, ALPHA_DB_PORT
import requests

jiwu = pymongo.MongoClient(ALPHA_DB_HOST, ALPHA_DB_PORT).jiwu


def choose_shelf():
    for i in [
        "AP2501144578938",
        "AP2501145150156",
        "AP2501150836492",
        "AP2501150881326",
        "AP2501162423093",
        "AP2501162436186",
        "AP2501162444038",
        "AP2501162448615",
        "AP2501162455714",
        "AP2501162464305",
        "AP2501163636842",
        "AP2501163639613",
        "AP2501163718003",
        "AP2501163738313",
        "AP2501163742966",
        "AP2501163750623",
        "AP2501163780130",
        "AP2501163790786",
        "AP2501163795292",
        "AP2501163801293",
        "AP2501163805004",
        "AP2501163809557",
        "AP2501163813899",
        "AP2501163829395",
        "AP2501163836281",
        "AP2501163843766",
        "AP2501163858527",
        "AP2501163865972",
        "AP2501163887969"
    ]:
        url = "https://erp.geehoop.com/api/backend/stock_in_order/in_stock_order"
        payload = {key: jiwu.stock_in_orders.find_one({"appointNo": i}).get(key) for key in
                   ['appointNo', 'receiptSkuCounts', 'failSkuCounts', 'otherUnAppointSkuCounts']}
        headers = {
            'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1MGE0YTg2ODNmOTE1YzM4ZDE4YzY0MCIsImlhdCI6MTczNzA4MTEwMiwiZXhwIjoxNzM3Njg1OTAyfQ.7fooeDnISsO2Y3o3sr8BXwtIBefMKOgpFTBaj_MLmok',
            'priority': 'u=1, i',
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
            'Accept': '*/*',
            'Host': 'erp.geehoop.com',
            'Connection': 'keep-alive'
        }
        print(payload)
        r = requests.post(url, headers=headers, json=payload).json()
        print(r)


def finish_shelf(file_path):
    arts = read_xlsx_file(file_path,3)
    sizes = read_xlsx_file(file_path, 4)
    payload = {}
    headers = {
        'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY1MGE0YTg2ODNmOTE1YzM4ZDE4YzY0MCIsImlhdCI6MTczNzA4MTEwMiwiZXhwIjoxNzM3Njg1OTAyfQ.7fooeDnISsO2Y3o3sr8BXwtIBefMKOgpFTBaj_MLmok',
        'priority': 'u=1, i',
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        'Accept': '*/*',
        'Host': 'erp.geehoop.com',
        'Connection': 'keep-alive'
    }
    for i in [
        "AP2501144578938",
        "AP2501145150156",
        "AP2501150836492",
        "AP2501150881326",
        "AP2501162423093",
        "AP2501162436186",
        "AP2501162444038",
        "AP2501162448615",
        "AP2501162455714",
        "AP2501162464305",
        "AP2501163636842",
        "AP2501163639613",
        "AP2501163718003",
        "AP2501163738313",
        "AP2501163742966",
        "AP2501163750623",
        "AP2501163780130",
        "AP2501163790786",
        "AP2501163795292",
        "AP2501163801293",
        "AP2501163805004",
        "AP2501163809557",
        "AP2501163813899",
        "AP2501163829395",
        "AP2501163836281",
        "AP2501163843766",
        "AP2501163858527",
        "AP2501163865972",
        "AP2501163887969"
    ]:
        url = f"https://erp.geehoop.com/api/backend/stock_in_order/shelf/{i}"
        response = requests.request("PUT", url, headers=headers, data=payload).json()
        print(response)


def switch_size():

    url = "https://apiv2.dingstock.net/trading/api/sale/backend/kream/management/sizes?sku=FN0429-010"
    payload = {}
    headers = {
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        'token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InUwVmRSQTBVcU0iLCJpc0RjU2FsZU1lcmNoYW50Ijp0cnVlLCJpYXQiOjE3Mzg3MTg4NzUsImV4cCI6MTczOTMyMzY3NX0.aUBzTxi_jdE0voAAeErwaU0OBiN-HCCt_MCRz2sTVh8',
        'Accept': '*/*',
        'Host': 'apiv2.dingstock.net',
        'Connection': 'keep-alive'
    }

    response = requests.request("GET", url, headers=headers, data=payload)

    print(response.text)


url = 'https://base.dahood.tech/platform/novelship/lists?cursor=0&limit=100'